﻿using System.Data;
using System.Windows;
using System.Windows.Controls;

namespace Visualizacao3D.Controls
{
    public class ExercicioFrame : ContentControl
    {
        static ExercicioFrame()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ExercicioFrame), new FrameworkPropertyMetadata(typeof(ExercicioFrame)));
        }

        #region Overrides

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (!(this.Content is Exercicio))
                throw new ConstraintException("O conteudo do ExercicioFrame não é um exercicio.");

            Button resetCamera = this.Template.FindName("resetCamera",this) as Button;
            if (resetCamera != null)
            {
                resetCamera.Click += new RoutedEventHandler(resetCamera_Click);
            }

            CheckBox mostrarGraficos = this.Template.FindName("mostrarGraficos",this) as CheckBox;
            if (mostrarGraficos != null)
            {
                mostrarGraficos.Checked += new RoutedEventHandler(mostrarGraficos_CheckedChanged);
                mostrarGraficos.Unchecked += new RoutedEventHandler(mostrarGraficos_CheckedChanged);
            }
        }

        #endregion

        #region Event Handlers

        void resetCamera_Click(object sender, RoutedEventArgs e)
        {
            ((Exercicio)Content).TrackballDecorator.ResetTrackball(500);
        }

        void mostrarGraficos_CheckedChanged(object sender, RoutedEventArgs e)
        {
            StackPanel selecaoGraficos = this.Template.FindName("selecaoGraficos", this) as StackPanel;
            if (((CheckBox)sender).IsChecked != true)
                foreach (RadioButton rb in selecaoGraficos.Children)
                {
                    rb.IsChecked = false;
                }
            else
                ((RadioButton)selecaoGraficos.Children[0]).IsChecked = true;
        }

        #endregion


        #region MostrarVetores

        /// <summary>
        /// MostrarVetores Dependency Property
        /// </summary>
        public static readonly DependencyProperty MostrarVetoresProperty =
            DependencyProperty.Register("MostrarVetores", typeof(bool), typeof(ExercicioFrame),
                new FrameworkPropertyMetadata((bool)true));

        /// <summary>
        /// Gets or sets the MostrarVetores property.  This dependency property 
        /// indicates MostrarVetores.
        /// </summary>
        public bool MostrarVetores
        {
            get { return (bool)GetValue(MostrarVetoresProperty); }
            set { SetValue(MostrarVetoresProperty, value); }
        }

        #endregion

        #region MostrarBarras

        /// <summary>
        /// MostrarBarras Dependency Property
        /// </summary>
        public static readonly DependencyProperty MostrarBarrasProperty =
            DependencyProperty.Register("MostrarBarras", typeof(bool), typeof(ExercicioFrame),
                new FrameworkPropertyMetadata((bool)true));

        /// <summary>
        /// Gets or sets the MostrarBarras property.  This dependency property 
        /// indicates ....
        /// </summary>
        public bool MostrarBarras
        {
            get { return (bool)GetValue(MostrarBarrasProperty); }
            set { SetValue(MostrarBarrasProperty, value); }
        }

        #endregion

        #region MostrarApoios

        /// <summary>
        /// MostrarApoios Dependency Property
        /// </summary>
        public static readonly DependencyProperty MostrarApoiosProperty =
            DependencyProperty.Register("MostrarApoios", typeof(bool), typeof(ExercicioFrame),
                new FrameworkPropertyMetadata((bool)true));

        /// <summary>
        /// Gets or sets the MostrarApoios property.  This dependency property 
        /// indicates ....
        /// </summary>
        public bool MostrarApoios
        {
            get { return (bool)GetValue(MostrarApoiosProperty); }
            set { SetValue(MostrarApoiosProperty, value); }
        }

        #endregion

        #region MostrarBoundingBox

        /// <summary>
        /// MostrarBoundingBox Dependency Property
        /// </summary>
        public static readonly DependencyProperty MostrarBoundingBoxProperty =
            DependencyProperty.Register("MostrarBoundingBox", typeof(bool), typeof(ExercicioFrame),
                new FrameworkPropertyMetadata((bool)false));

        /// <summary>
        /// Gets or sets the MostrarBoundingBox property.  This dependency property 
        /// indicates ....
        /// </summary>
        public bool MostrarBoundingBox
        {
            get { return (bool)GetValue(MostrarBoundingBoxProperty); }
            set { SetValue(MostrarBoundingBoxProperty, value); }
        }

        #endregion

        #region MostrarEixos

        /// <summary>
        /// MostrarEixos Dependency Property
        /// </summary>
        public static readonly DependencyProperty MostrarEixosProperty =
            DependencyProperty.Register("MostrarEixos", typeof(bool), typeof(ExercicioFrame),
                new FrameworkPropertyMetadata((bool)false));

        /// <summary>
        /// Gets or sets the MostrarEixos property.  This dependency property 
        /// indicates ....
        /// </summary>
        public bool MostrarEixos
        {
            get { return (bool)GetValue(MostrarEixosProperty); }
            set { SetValue(MostrarEixosProperty, value); }
        }

        #endregion


        #region MostrarGraficosNormais

        /// <summary>
        /// MostrarGraficosNormais Dependency Property
        /// </summary>
        public static readonly DependencyProperty MostrarGraficosNormaisProperty =
            DependencyProperty.Register("MostrarGraficosNormais", typeof(bool), typeof(ExercicioFrame),
                new FrameworkPropertyMetadata((bool)false));

        /// <summary>
        /// Gets or sets the MostrarGraficosNormais property.  This dependency property 
        /// indicates ....
        /// </summary>
        public bool MostrarGraficosNormais
        {
            get { return (bool)GetValue(MostrarGraficosNormaisProperty); }
            set { SetValue(MostrarGraficosNormaisProperty, value); }
        }

        #endregion

        #region MostrarGraficosCortantes

        /// <summary>
        /// MostrarGraficosCortantes Dependency Property
        /// </summary>
        public static readonly DependencyProperty MostrarGraficosCortantesProperty =
            DependencyProperty.Register("MostrarGraficosCortantes", typeof(bool), typeof(ExercicioFrame),
                new FrameworkPropertyMetadata((bool)false));

        /// <summary>
        /// Gets or sets the MostrarGraficosCortantes property.  This dependency property 
        /// indicates ....
        /// </summary>
        public bool MostrarGraficosCortantes
        {
            get { return (bool)GetValue(MostrarGraficosCortantesProperty); }
            set { SetValue(MostrarGraficosCortantesProperty, value); }
        }

        #endregion

        #region MostrarGraficosFletores

        /// <summary>
        /// MostrarGraficosFletores Dependency Property
        /// </summary>
        public static readonly DependencyProperty MostrarGraficosFletoresProperty =
            DependencyProperty.Register("MostrarGraficosFletores", typeof(bool), typeof(ExercicioFrame),
                new FrameworkPropertyMetadata((bool)false));

        /// <summary>
        /// Gets or sets the MostrarGraficosFletores property.  This dependency property 
        /// indicates ....
        /// </summary>
        public bool MostrarGraficosFletores
        {
            get { return (bool)GetValue(MostrarGraficosFletoresProperty); }
            set { SetValue(MostrarGraficosFletoresProperty, value); }
        }

        #endregion

        #region MostrarGraficosTorcores

        /// <summary>
        /// MostrarGraficosTorcores Dependency Property
        /// </summary>
        public static readonly DependencyProperty MostrarGraficosTorcoresProperty =
            DependencyProperty.Register("MostrarGraficosTorcores", typeof(bool), typeof(ExercicioFrame),
                new FrameworkPropertyMetadata((bool)false));

        /// <summary>
        /// Gets or sets the MostrarGraficosTorcores property.  This dependency property 
        /// indicates ....
        /// </summary>
        public bool MostrarGraficosTorcores
        {
            get { return (bool)GetValue(MostrarGraficosTorcoresProperty); }
            set { SetValue(MostrarGraficosTorcoresProperty, value); }
        }

        #endregion
    }
}
